import request from "@/utils/request";
import {serverIp} from "../../public/config.js";
const API_BASE_URL = `http://${serverIp}:8081/jdyfy`;
/**
 * 项目API请求
 *
 */

//项目分页查询
export const getProjectPage = (pageNum, pageSize, projectNumber, projectName,procurementMethod) =>{
    return request.get(`${API_BASE_URL}/projectPage`,{
        params: {
            pageNum,
            pageSize,
            projectNumber,
            projectName,
            procurementMethod
        }
    }).then(res => {
        return res.data;
        })
};

//历史项目分页查询
export const getHistoProjectPage = (pageNum, pageSize, projectNumber, projectName,procurementMethod) =>{
    return request.get(`${API_BASE_URL}/histoProjectPage`,{
        params: {
            pageNum,
            pageSize,
            projectNumber,
            projectName,
            procurementMethod
        }
    }).then(res => {
        return res.data;
    })
};

// 通过状态排序，进行项目分页查询
export const getProjectPageSort = (pageNum, pageSize, projectNumber, projectName,procurementMethod) =>{
    return request.get(`${API_BASE_URL}/projectPageSortByStatus`,{
        params: {
            pageNum,
            pageSize,
            projectNumber,
            projectName,
            procurementMethod
        }
    }).then(res => {
        return res.data;
    })
};

// 通过状态进行项目分页查询
export const getProjectPageByStatus = (pageNum, pageSize, projectNumber, projectName,procurementMethod,statusStart,statusEnd) =>{
    return request.get(`${API_BASE_URL}/projectPageByStatus`,{
        params: {
            pageNum,
            pageSize,
            projectNumber,
            projectName,
            procurementMethod,
            statusStart,
            statusEnd
        }
    }).then(res => {
        return res.data;
    })
};

// 通过状态范围进行项目分页查询
export const getProjectPageByStatusSpace = (pageNum, pageSize, projectNumber, projectName,procurementMethod,annoStatusStart,annoStatusEnd) =>{
    return request.get(`${API_BASE_URL}/projectPageByStatusSpace`,{
        params: {
            pageNum,
            pageSize,
            projectNumber,
            projectName,
            procurementMethod,
            annoStatusStart,
            annoStatusEnd
        }
    }).then(res => {
        return res.data;
    })
};

/**
 * 获取所有项目
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProjectList = () =>{
    return request.get(`${API_BASE_URL}/projects`).then(res => {
        return res.data;
    })
};

/**
 * 通过状态获取所有项目
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProjectsByStatus = (annoStatusStart,annoStatusEnd) =>{
    return request.get(`${API_BASE_URL}/getProjectsByStatus`, {params: {annoStatusStart,annoStatusEnd}}).then(res => {
        return res.data;
    })
};

/**
 * 根据状态获取项目
 * @param status
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProjectsBySStatus = (status) =>{
    return request.get(`${API_BASE_URL}/getProjectsBySStatus`, {params: {status}}).then(res => {
        return res.data;
    })
};

/**
 * 获取项目总数
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProjectTotal = () =>{
    return request.get(`${API_BASE_URL}/projectTotal`).then(res => {
        return res.data;
    })
};

/**
 * 根据项目ID查询项目信息
 * @param projectId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProjectById = (projectId) =>{
    return request.get(`${API_BASE_URL}/project/${projectId}`)
        .then(res => {
            return res.data;
        })
};

/**
 * 根据项目编号查询项目信息
 * @param projectNumber
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getProjectByNumber = (projectNumber) =>{
    return request.get(`${API_BASE_URL}/projectByNumber/${projectNumber}`)
        .then(res => {
            return res.data;
        })
};

//添加或修改项目
export const addProject = (form) =>{
    return request.post(`${API_BASE_URL}/project/save`, form)
        .then(res => {
            return res;
        });
};

//删除项目
export const deleteProject = (ids) =>{
    return request.delete(`${API_BASE_URL}/project/dels`, {data: ids})
        .then(res => {
        if (res.status < 200 || res.status >= 300) {
            throw new Error('网络错误');
        }
        return 1;
    })

};

//获取科室项目，作柱状图
export const getSPBar = () =>{
    return request.get(`${API_BASE_URL}/SPBar`)
        .then(res => {
        return res.data;
    })
};

//获取项目类型，作饼图
export const getPT = () =>{
    return request.get(`${API_BASE_URL}/PT`)
        .then(res => {
            return res.data;
        })
};

//获取采购方式，作饼图
export const getPM = () =>{
    return request.get(`${API_BASE_URL}/PM`)
        .then(res => {
            return res.data;
        })
};

//添加中标项目
export const addWinnotiProject = (form) =>{
    return request.post(`${API_BASE_URL}/winnotiProject/save`, form)
        .then(res => {
            return res;
        });
};

//根据成交人查询中标项目
export const getWinnotiProjectByDealerPage = (pageNum, pageSize, projectName, projectNumber,departmentName) =>{
    return request.get(`${API_BASE_URL}/winnotiProjectByDealerPage`,{
        params: {
            pageNum,
            pageSize,
            projectName,
            projectNumber,
            departmentName
        }
    }).then(res => {
        return res.data;
    })
};

//根据项目编号查询中标项目
export const getWinnotiByProjectNumber = (projectNumber) =>{
    return request.get(`${API_BASE_URL}/winnotiByProjectNumber/${projectNumber}`)
        .then(res => {
            return res.data;
        })
};

//获取中标项目总数
export const getWinnotiProjectCount = () =>{
    return request.get(`${API_BASE_URL}/winnotiProjectCount`)
        .then(res => {
            return res.data;
        })
};

//根据企业名称获取中标金额
export const getTotalAmountByDepartmentName = (departmentName) =>{
    return request.get(`${API_BASE_URL}/totalAmountByDepartmentName`, {params: {departmentName}})
        .then(res => {
            return res.data;
        })
};

//获取成交总额
export const getTotalAmount = () =>{
    return request.get(`${API_BASE_URL}/totalAmount`)
        .then(res => {
            return res.data;
        })
};

// 添加或修改通知
export const addNotification = (form) =>{
    return request.post(`${API_BASE_URL}/notification/save`, form)
        .then(res => {
            return res.data;
        });
};

//获取科室中标项目总数
export const getAdCountByDepartment = (departmentName) =>{
    return request.get(`${API_BASE_URL}/adCountByDepartment`, {params: {departmentName}})
        .then(res => {
            return res.data;
        })
};

//获取科室中标项目总数
export const getWinnotiProjectCountByDepartment = (departmentName) =>{
    return request.get(`${API_BASE_URL}/winnotiProjectCountByDepartment`, {params: {departmentName}})
        .then(res => {
            return res.data;
        })
};